<?php
/**
 * Copyright 2011  SURFfoundation
 * 
 * This file is part of ESCAPE.
 * 
 * ESCAPE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ESCAPE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ESCAPE.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * For more information:
 * http://escapesurf.wordpress.com/
 * http://www.surffoundation.nl/
 * 
 * Contact: d.vierkant@utwente.nl
 * 
 * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3
 */
?>
<?php
	/* @var $repositoryUi escape_repositoryui_RepositoryUi */
	$repositoryUi =& $this->requestAttributes['repositoryUi'];
	/* @var $oreObject escape_repository_OreObject */
	$oreObject =& $this->requestAttributes['oreObject'];
	/* @var $aggregation escape_repository_OreAggregation */
	$aggregation =& $this->requestAttributes['aggregation'];
	
	$attachmentMimeType = $this->requestAttributes['attachmentMimeType'];
	
	$gadgetModeUrlParameter = '';
	if($repositoryUi->isGadgetMode())
	{
		$gadgetModeUrlParameter = '?gadget=1';
	}
	
	$repositoryUi->setTemplateFromAggregation($aggregation);
	
	$templateVariables = array();
	$templateVariables['title'] = 'Upload';
	$this->requestAttributes['templateVariables'] =& $templateVariables;
?>
<?php $this->displayHeader(); ?>

<div class="escape_Section">
<span class="escape_SectionTitle">Attach a file</span>
</div>

<div class="escape_Selection">
<?php
		$repositoryUi->displayOreObject($aggregation, $oreObject, false);
?>
</div>

<div class="escape_Upload">

<form action="<?php print $repositoryUi->getActionLinkById('upload', $oreObject->getId()) . $gadgetModeUrlParameter; ?>" method="post" enctype="multipart/form-data">

<table class="escape_FormTable">
<tr>
<td>
Select a file:
</td>
<td>
<input type="file" name="file" />
</td>
</tr>
</table>

<?php
		if($oreObject->getAttachmentMimeType() === null)
		{
?>
<input type="submit" value="Upload file" />
<?php
		}
		else
		{
?>
<input type="submit" value="Replace file" />
<?php
		}
?>
<button onclick="escape_escapeUi.redirectToResourceById('edit', <?php print htmlspecialchars(json_encode($oreObject->getId())); ?>); return false">Cancel</button>

</form>

</div>

<?php $this->displayFooter(); ?>
